<h2>Заявки</h2>

<p>Чтобы перейти к списку заявок по конкретной тематике — выберите ее название.</p>

<?php

if ( ! count( $stat ) )
{
  print '<p>Заявок пока нет.</p>';
}
else
{
  ?>
  <table>
    <tr>
      <td></td>
      <td></td>
      <td><img src='/images/status/small/pending.png' alt='Проверка' title='Проверка'></td>
      <td><img src='/images/status/small/waiting.png' alt='Ожидание' title='Ожидание'></td>
      <td><img src='/images/status/small/approved.png' alt='Принято' title='Принято'></td>
      <td><img src='/images/status/small/disapproved.png' alt='Отклонено' title='Отклонено'></td>      
    </tr>
  <?php
  
  foreach ( $topics as $topic_code => $topic )
  {
    $counters = array(
      'pending'      => 0,
      'waiting'      => 0,
      'approved'     => 0,
      'disapproved'  => 0,
    );
  
    foreach( $stat as $bit )
    {
      if ( $bit['code'] != $topic_code ) continue;
     
      $counters[ $bit['status'] ] = $bit['count'];
    }
    
    ?>
      <tr>
        <td style='text-align:left;font-size:14px;'><?php print $topic['card'] ?></td>
        <td style='text-align:left;font-size:14px;'><a href='/orgs/requests/<?php print $topic_code?>/'><?php print $topic['title'] ?></a></td>
        <td style='text-align:center;font-size:14px;'><?php print $counters['pending'] ?></td>
        <td style='text-align:center;font-size:14px;'><?php print $counters['waiting'] ?></td>
        <td style='text-align:center;font-size:14px;'><?php print $counters['approved'] ?></td>
        <td style='text-align:center;font-size:14px;'><?php print $counters['disapproved'] ?></td>      
      </tr>
    <?php    
  }
  
  print '</table>'; 
  
  
}